/*打断、终止一个线程——方法1*/
public class Demo9 {
    private static boolean flag=true;

    public static void main(String[] args) throws InterruptedException {
        Thread t=new Thread(()->{
            while(flag){
                System.out.println("hello thread");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    //throw new RuntimeException(e);
                    e.printStackTrace();//打印报错
                }
            }
        });
        t.start();

        System.out.println("hello main");
        Thread.sleep(3000);
        flag=false;
        System.out.println("让t线程终止");
    }
}
//这个方法太low